package com.sfx.jedis.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-18
 * Time: 13:06
 */
//jedis连接池
public class JedisConnectFactory {

    private static final JedisPool jedispool;
    static {
        //配置jedis连接池
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        //设置最大连接数
        poolConfig.setMaxTotal(8);
        //设置最大空闲接数
        poolConfig.setMaxIdle(6);
        //设置最小空闲连接数
        poolConfig.setMinIdle(0);
        //初始化jedisPool->连接池配置 + ip + 端口 + 超时时间 + 密码
        jedispool = new JedisPool(poolConfig,"101.42.177.102",
                6379,1000,"123321");
    }

    //从jedis连接池中获取jedis对象
    public static Jedis getJedis() {
        return jedispool.getResource();
    }
}
